<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .wrap {
            width: 400px;
            height: 400px;
            background-color: #6ff;
            overflow: hidden;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #f66;
            margin-left: 100px;
            margin-top: 100px;
        }

        .box img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="box">
            <img src="../img/1.jpg" alt="">
        </div>
    </div>
</body>
<script>
    // 事件冒泡 是浏览器默认的事件传播机制 

    // 需求: closeBtn事件触发之后 不在向外层冒泡(阻止谁 就在谁上写)
    // 阻止事件冒泡 (阻止事件向外层传播 )

    // 常规浏览器
    // e.stopPropagation();

    // IE低版本
    // e.cancelBubble = true;   //是否阻止冒泡 (默认false:不阻止  true:阻止)

    // 兼容写法
    // if(e.stopPropagation){
    //     e.stopPropagation();
    // }else{
    //     e.cancelBubble = true;
    // }


    var wrap = document.querySelector(".wrap");
    var box = document.querySelector(".box");

    wrap.onmousedown = function (e) {
        var e = e || window.event;
        var target = e.target || e.srcElement;
        console.log("点击了wrap");
    }
    box.onclick = function (e) {
        var e = e || window.event;
        var target = e.target || e.srcElement;
        console.log("点击了box", target);

    }
    box.onmousedown = function (e) {
        var e = e || window.event;
        var target = e.target || e.srcElement;
        if (e.stopPropagation) {
            e.stopPropagation();
        } else {
            e.cancelBubble = true;
        }
    }
</script>

</html>